// gmvector.cpp : contains functions to work with tables that are vectors
//$Id: gmVector.cpp 16 2009-08-14 17:38:36Z brwarner2 $
#include "stdafx.h"

gmTableObject* CreateVector( gmMachine& gm, float x, float z )
{
	//Create a new table object
	gmTableObject* vec = gm.AllocTableObject();
	vec->Set(&gm, "x", gmVariable(x));
	vec->Set(&gm, "z", gmVariable(z));
	return vec;
}

gmTableObject* CreateVector( gmMachine& gm, const bug::math::CVector& v )
{
	return CreateVector(gm, v.m_x, v.m_z);
}

bug::math::CVector GetVector( gmMachine& gm, gmTableObject* vec)
{
	//Get floats
	float x = vec->Get(&gm, "x").GetFloatSafe();
	float z = vec->Get(&gm, "z").GetFloatSafe();

	//Return vector
	return bug::math::CVector(x, 0.0f, z);
}

void SetVector( gmMachine& gm, gmTableObject* vec, const bug::math::CVector& v )
{
	//Set variables
	vec->Set(&gm, "x", gmVariable(v.m_x));
	vec->Set(&gm, "z", gmVariable(v.m_z));
}